package com.javabasic.algorithm.sword_of_offer;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/1/13 10:55 下午
 */
public class 剑指_Offer_27_二叉树的镜像 {


    /**
     * DFS
     * @param root
     * @return
     */
    public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return root;
        }
        TreeNode left = root.left;
        TreeNode right = root.right;
        if (left == null && right == null) {
            return root;
        }
        if (left != null) {
            mirrorTree(left);
        }
        if (right != null) {
            mirrorTree(right);
        }
        TreeNode temp = left;
        root.left = root.right;
        root.right = temp;
        return root;
    }
}
